package com.magenta.maxoptra.utils;

import java.io.Serializable;
import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 * Project: Mobile Asset Manager
 * Author: Sergey Budaev
 * Created: 19.12.2007 19:29:22
 * <p/>
 * Copyright (c) 1999-2007 Magenta Corporation Ltd. All Rights Reserved.
 * Magenta Technology proprietary and confidential.
 * Use is subject to license terms.
 */
public class Point implements Serializable {
    private static final long serialVersionUID = -4613969720817409707L;

    private double longitude;
    private double latitude;

    public Point() {
    }


    public Point(double longitude, double latitude) {
        this.longitude = longitude;
        this.latitude = latitude;
    }

    public Point(Double longitude, Double latitude, Integer rounded) {
        if (rounded != null && rounded > 0) {
            this.longitude = new BigDecimal(longitude).setScale(rounded, RoundingMode.HALF_UP).doubleValue();
            this.latitude = new BigDecimal(latitude).setScale(rounded, RoundingMode.HALF_UP).doubleValue();
        } else {
            this.longitude = longitude;
            this.latitude = latitude;
        }
    }

    public double getLongitude() {
        return longitude;
    }

    public void setLongitude(double longitude) {
        this.longitude = longitude;
    }

    public double getLatitude() {
        return latitude;
    }

    public void setLatitude(double latitude) {
        this.latitude = latitude;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Point point = (Point) o;

        if (Double.compare(point.latitude, latitude) != 0) return false;
        if (Double.compare(point.longitude, longitude) != 0) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result;
        long temp;
        temp = longitude != +0.0d ? Double.doubleToLongBits(longitude) : 0L;
        result = (int) (temp ^ (temp >>> 32));
        temp = latitude != +0.0d ? Double.doubleToLongBits(latitude) : 0L;
        result = 31 * result + (int) (temp ^ (temp >>> 32));
        return result;
    }

    @Override
    public String toString() {
        return "[long:"+longitude+" lat:"+latitude+"]";
    }
}
